package com.ang.juc;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import java.util.concurrent.atomic.AtomicInteger;

public class Rice {

    public AtomicInteger count = new AtomicInteger(3000);

    public Object lock = new Object();

    class TicktWindow{

        public void sell(){
            count.decrementAndGet();
        }
    }

    public void test() throws Exception {
        List<Thread> threads = new Vector<>();
        for (int i = 0; i < 5000; i++) {
            Thread t = new Thread(()->{
                TicktWindow tw = new TicktWindow();
                tw.sell();
            });
            t.start();
            threads.add(t);
        }

        for (Thread t : threads) {
            t.join();
        }

        System.out.println(count);
    }

    public static void main(String[] args) throws Exception  {
        Rice rice = new Rice();
        rice.test();
    }

}
